(function(vc){
    vc.extends({
        propTypes: {
           emitChooseAffiliateProduct:vc.propTypes.string,
           emitLoadData:vc.propTypes.string
        },
        data:{
            chooseAffiliateProductInfo:{
                affiliateProducts:[],
                _currentAffiliateProductName:'',
            }
        },
        _initMethod:function(){
        },
        _initEvent:function(){
            vc.on('chooseAffiliateProduct','openChooseAffiliateProductModel',function(_param){
                $('#chooseAffiliateProductModel').modal('show');
                vc.component._refreshChooseAffiliateProductInfo();
                vc.component._loadAllAffiliateProductInfo(1,10,'');
            });
        },
        methods:{
            _loadAllAffiliateProductInfo:function(_page,_row,_name){
                var param = {
                    params:{
                        page:_page,
                        row:_row,
                        communityId:vc.getCurrentCommunity().communityId,
                        name:_name
                    }
                };

                //发送get请求
               vc.http.apiGet('affiliateProduct.listAffiliateProducts',
                             param,
                             function(json){
                                var _affiliateProductInfo = JSON.parse(json);
                                vc.component.chooseAffiliateProductInfo.affiliateProducts = _affiliateProductInfo.affiliateProducts;
                             },function(){
                                console.log('请求失败处理');
                             }
                           );
            },
            chooseAffiliateProduct:function(_affiliateProduct){
                if(_affiliateProduct.hasOwnProperty('name')){
                     _affiliateProduct.affiliateProductName = _affiliateProduct.name;
                }
                vc.emit($props.emitChooseAffiliateProduct,'chooseAffiliateProduct',_affiliateProduct);
                vc.emit($props.emitLoadData,'listAffiliateProductData',{
                    affiliateProductId:_affiliateProduct.affiliateProductId
                });
                $('#chooseAffiliateProductModel').modal('hide');
            },
            queryAffiliateProducts:function(){
                vc.component._loadAllAffiliateProductInfo(1,10,vc.component.chooseAffiliateProductInfo._currentAffiliateProductName);
            },
            _refreshChooseAffiliateProductInfo:function(){
                vc.component.chooseAffiliateProductInfo._currentAffiliateProductName = "";
            }
        }

    });
})(window.vc);
